<?php
/**
 * @ClassName: App
 * @Description: 应用设置
 * @author: wyaohu
 * @Date: 2024-09-14 10:10
 * @Version: V1.0.0
 */

namespace app\admin\controller\setting;

use app\common\model;
use think\Controller;
use tpext\builder\common\Builder;

class App extends Controller
{
    protected function initialize()
    {
        parent::initialize();
    }

    function wechat_config()
    {
		// 获取数据
		$config_data = model\SystemConfig::where('config_tab_id', 1)->find();
		
        // 接收并保存参数
        if (request()->isPost()) {
            $data = $this->request->param();
			$res = true;
            if ($res) {
                $this->success('修改成功', url('/admin/setting.app/wechat_config'));
            } else {
                $this->error('修改失败', url('/admin/setting.app/wechat_config'));
            }
		}
		
        $builder = Builder::getInstance('微信公众号配置');
        $builder->column(1);
        $form = $builder->column(10)->form();
        $form->fill($config_data);
		
        $form->tab('公众号开发者信息');
        $form->text('app_id', 'AppID')->help('微信公众号AppID');
        $form->text('app_secret', 'AppSecret')->help('微信公众号AppSecret');
        $form->tabEnd();
		
        $form->tab('服务器配置');
        $form->text('encoding_aes_key', 'EncodingAESKey')->help('公众号消息加解密Key,在使用安全模式情况下要填写该值，请先在管理中心修改，然后填写该值，仅限服务号和认证订阅号');
        $form->text('token', '微信验证TOKEN');
        $form->text('api_url', '接口地址');
        $form->text('msg_enc_dec_way', '消息加解密方式');
        $form->tabEnd();
		
        $form->tab('微信公众号');
        $form->text('is_new_member', '关注公众号是否生成用户');
        $form->tabEnd();
		
        return $builder;
    }

    function routine_config()
    {
		// 获取数据
		$config_data = model\SystemConfig::where('config_tab_id', 2)->find();
		
        // 接收并保存参数
        if (request()->isPost()) {
            $data = $this->request->param();
			$res = true;
            if ($res) {
                $this->success('修改成功', url('/admin/setting.app/routine_config'));
            } else {
                $this->error('修改失败', url('/admin/setting.app/routine_config'));
            }
		}
		
        $builder = Builder::getInstance('微信小程序配置');
        $builder->column(1);
        $form = $builder->column(10)->form();
        $form->fill($config_data);
		
        $form->tab('基础配置');
        $form->text('app_id', 'AppID')->help('微信小程序AppID');
        $form->text('app_secret', 'AppSecret')->help('微信小程序AppSecret');
        $form->text('app_name', '小程序名称');
        $form->text('mini_record_number', '备案号')->help('小程序备案号');
        $form->tabEnd();
		
        return $builder;
    }

    function pc_config()
    {
		// 获取数据
		$config_data = model\SystemConfig::where('config_tab_id', 3)->find();
		
        // 接收并保存参数
        if (request()->isPost()) {
            $data = $this->request->param();
			$res = true;
            if ($res) {
                $this->success('修改成功', url('/admin/setting.app/pc_config'));
            } else {
                $this->error('修改失败', url('/admin/setting.app/pc_config'));
            }
		}
		
        $builder = Builder::getInstance('微信小程序配置');
        $builder->column(1);
        $form = $builder->column(10)->form();
        $form->fill($config_data);
		
        $form->tab('基础配置');
        $form->text('logo', 'PC端LOGO');
        $form->text('contact_mobile', '联系电话');
        $form->text('company_address', '公司地址');
        $form->text('copyright', '版权信息');
        $form->text('web_title', 'SEO标题');
        $form->text('keywords', '关键词');
        $form->text('description', '网站描述');
        $form->text('web_record_number', '备案号');
        $form->text('security_number', '联网备案号（网安备案）');
        $form->tabEnd();
		
        $form->tab('微信开放平台');
        $form->text('app_id', 'AppID')->help('公众开放平台网站应用的APPID');
        $form->text('app_secret', 'AppSecret')->help('公众开放平台网站应用的AppSecret');
        $form->tabEnd();
		
        $form->tab('友情链接');
        $form->tabEnd();
		
        $form->tab('备案信息');
        $form->tabEnd();
		
        return $builder;
    }

    function app_config()
    {
		// 获取数据
		$config_data = model\SystemConfig::where('config_tab_id', 4)->find();
		
        // 接收并保存参数
        if (request()->isPost()) {
            $data = $this->request->param();
			$res = true;
            if ($res) {
                $this->success('修改成功', url('/admin/setting.app/app_config'));
            } else {
                $this->error('修改失败', url('/admin/setting.app/app_config'));
            }
		}
		
        $builder = Builder::getInstance('微信小程序配置');
        $builder->column(1);
        $form = $builder->column(10)->form();
        $form->fill($config_data);
		
        $form->tab('基础配置');
        $form->text('app_id', '移动应用APPID')->help('公众平台开放移动应用的APPID');
        $form->text('app_secret', '移动应用AppSecret')->help('公众平台开放移动应用的AppSecret');
        $form->text('app_record_number', 'APP备案号');
        $form->tabEnd();
		
        return $builder;
    }

    function douyin_config()
    {
		// 获取数据
		$config_data = model\SystemConfig::where('config_tab_id', 5)->find();
		
        // 接收并保存参数
        if (request()->isPost()) {
            $data = $this->request->param();
			$res = true;
            if ($res) {
                $this->success('修改成功', url('/admin/setting.app/app_config'));
            } else {
                $this->error('修改失败', url('/admin/setting.app/app_config'));
            }
		}
		
        $builder = Builder::getInstance('抖音配置');
        $builder->column(1);
        $form = $builder->column(10)->form();
        $form->fill($config_data);
		
        $form->tab('基础配置');
        $form->text('app_id', 'APPID')->help('抖音小程序APPID');
        $form->text('app_secret', 'AppSecret')->help('抖音小程序AppSecret');
        $form->text('app_salt', 'AppSalt')->help('抖音小程序支付秘钥');
        $form->text('pay_token', 'payToken')->help('抖音小程序支付Token');
        $form->text('mini_record_number', '小程序备案号');
        $form->tabEnd();
		
        return $builder;
    }

    function alipay_config()
    {
		// 获取数据
		$config_data = model\SystemConfig::where('config_tab_id', 6)->find();
		
        // 接收并保存参数
        if (request()->isPost()) {
            $data = $this->request->param();
			$res = true;
            if ($res) {
                $this->success('修改成功', url('/admin/setting.app/app_config'));
            } else {
                $this->error('修改失败', url('/admin/setting.app/app_config'));
            }
		}
		
        $builder = Builder::getInstance('支付宝配置');
        $builder->column(1);
        $form = $builder->column(10)->form();
        $form->fill($config_data);
		
        $form->tab('基础配置');
        $form->text('app_id', 'APPID')->help('支付宝小程序APPID');
        $form->text('app_secret', 'AppSecret')->help('支付宝小程序AppSecret');
        $form->text('mini_record_number', '小程序备案号');
        $form->tabEnd();
		
        return $builder;
    }

}